package com.ruoyi.web.controller.coalmine;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.coalmine.domain.Coalmine;
import com.ruoyi.coalmine.service.ICoalmineService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 生产经营单位信息Controller
 * 
 * @author zbw
 * @date 2022-07-11
 */
@RestController
@RequestMapping("/coalmine/manage")
public class CoalmineController extends BaseController
{
    @Autowired
    private ICoalmineService coalmineService;

    /**
     * 查询生产经营单位信息列表
     */
    @PreAuthorize("@ss.hasPermi('coalmine:manage:list')")
    @GetMapping("/list")
    public TableDataInfo list(Coalmine coalmine)
    {
        startPage();
        List<Coalmine> list = coalmineService.selectCoalmineList(coalmine);
        return getDataTable(list);
    }

    /**
     * 导出生产经营单位信息列表
     */
    @PreAuthorize("@ss.hasPermi('coalmine:manage:export')")
    @Log(title = "生产经营单位信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Coalmine coalmine)
    {
        List<Coalmine> list = coalmineService.selectCoalmineList(coalmine);
        ExcelUtil<Coalmine> util = new ExcelUtil<Coalmine>(Coalmine.class);
        util.exportExcel(response, list, "生产经营单位信息数据");
    }

    /**
     * 获取生产经营单位信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('coalmine:manage:query')")
    @GetMapping(value = "/{unitId}")
    public AjaxResult getInfo(@PathVariable("unitId") String unitId)
    {
        return AjaxResult.success(coalmineService.selectCoalmineByUnitId(unitId));
    }

    /**
     * 新增生产经营单位信息
     */
    @PreAuthorize("@ss.hasPermi('coalmine:manage:add')")
    @Log(title = "生产经营单位信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Coalmine coalmine)
    {
        return toAjax(coalmineService.insertCoalmine(coalmine));
    }

    /**
     * 修改生产经营单位信息
     */
    @PreAuthorize("@ss.hasPermi('coalmine:manage:edit')")
    @Log(title = "生产经营单位信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Coalmine coalmine)
    {
        return toAjax(coalmineService.updateCoalmine(coalmine));
    }

    /**
     * 删除生产经营单位信息
     */
    @PreAuthorize("@ss.hasPermi('coalmine:manage:remove')")
    @Log(title = "生产经营单位信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{unitIds}")
    public AjaxResult remove(@PathVariable String[] unitIds)
    {
        return toAjax(coalmineService.deleteCoalmineByUnitIds(unitIds));
    }
}
